/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jschoolmanagerportable.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "NOTAS")
@NamedQueries({
    @NamedQuery(name = "Nota.findById", query = "SELECT n FROM Nota n WHERE n.id = :id"), 
    @NamedQuery(name = "Nota.findByPeriodo", query = "SELECT n FROM Nota n WHERE n.periodo = :periodo"), 
    @NamedQuery(name = "Nota.findByNnota", query = "SELECT n FROM Nota n WHERE n.nnota = :nnota"), 
    @NamedQuery(name = "Nota.findByNota", query = "SELECT n FROM Nota n WHERE n.nota = :nota"),
    @NamedQuery(name = "Nota.findByAsignaturaAlumno", query = "SELECT n FROM Nota n WHERE n.idalumno = :alumno and n.idasignatura= :asignatura order by n.nnota"),
    @NamedQuery(name = "Nota.findByAsignaturaAlumnoPeriodo", query = "SELECT n FROM Nota n WHERE n.idalumno = :alumno and n.idasignatura= :asignatura and n.periodo= :periodo order by n.nnota"),
    @NamedQuery(name = "Nota.findByAsignaturaAlumnoPeriodoNNota", query = "SELECT n FROM Nota n WHERE n.idalumno = :alumno and n.idasignatura= :asignatura and n.periodo= :periodo and n.nnota = :nnota order by n.nnota")    
})
public class Nota implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy=GenerationType.TABLE, generator="notas")
    @TableGenerator(name="notas", table="sequencer", pkColumnName="class_name",valueColumnName="class_id")    
    private Integer id;
    @Column(name = "PERIODO", nullable = false)
    private int periodo;
    @Column(name = "NNOTA", nullable = false)
    private int nnota;
    @Column(name = "NOTA", nullable = false)
    private double nota;
    @JoinColumn(name = "IDALUMNO", referencedColumnName = "ID")
    @ManyToOne
    private Alumno idalumno;
    @JoinColumn(name = "IDASIGNATURA", referencedColumnName = "ID")
    @ManyToOne
    private Asignatura idasignatura;

    public Nota() {
    }

    public Nota(Integer id) {
        this.id = id;
    }

    public Nota(Integer id, int periodo, int nnota, double nota) {
        this.id = id;
        this.periodo = periodo;
        this.nnota = nnota;
        this.nota = nota;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public int getPeriodo() {
        return periodo;
    }

    public void setPeriodo(int periodo) {
        int oldPeriodo = this.periodo;
        this.periodo = periodo;
        changeSupport.firePropertyChange("periodo", oldPeriodo, periodo);
    }

    public int getNnota() {
        return nnota;
    }

    public void setNnota(int nnota) {
        int oldNnota = this.nnota;
        this.nnota = nnota;
        changeSupport.firePropertyChange("nnota", oldNnota, nnota);
    }

    public double getNota() {
        return nota;
    }

    public void setNota(double nota) {
        double oldNota = this.nota;
        this.nota = nota;
        changeSupport.firePropertyChange("nota", oldNota, nota);
    }

    public Alumno getIdalumno() {
        return idalumno;
    }

    public void setIdalumno(Alumno idalumno) {
        Alumno oldIdalumno = this.idalumno;
        this.idalumno = idalumno;
        changeSupport.firePropertyChange("idalumno", oldIdalumno, idalumno);
    }

    public Asignatura getIdasignatura() {
        return idasignatura;
    }

    public void setIdasignatura(Asignatura idasignatura) {
        Asignatura oldIdasignatura = this.idasignatura;
        this.idasignatura = idasignatura;
        changeSupport.firePropertyChange("idasignatura", oldIdasignatura, idasignatura);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Nota)) {
            return false;
        }
        Nota other = (Nota) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return String.valueOf(this.getNnota());
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

}
